/* Created by web-design Ver 1.0.9 */
import fetch from '@/utils/fetch'
import { getDatas, formatResponse } from '@/utils/data-utils'
export const getDatasByDataSource = (preload = {}) => {
    return new Promise((resolve, reject) => {
        const params = preload.params
        const pageObj = preload.pageObj
        const dSource = preload.dataSource
        if (dSource && dSource.api) {
            fetch(dSource.api, { query: getDatas(dSource.type, dSource.id, params, pageObj) }, { method: 'post' }).then((res) => {
                const responseKey = dSource.responseKey || 'data.getDatas'
                const result = formatResponse(res, responseKey)
                if (result instanceof Error) {
                    reject(result)
                } else {
                    resolve(result)
                }
            }).catch((e) => {
                reject(e)
            })
        } else {
            resolve({})
        }
    })
}
export const getDictItemsByCode = (code) => {
    return fetch('/api/cscpDictItemsByCriteria', { 'dictCode.equals': code }, { method: 'get' }).then(res => {
        return res.data || []
    }).catch(() => {
        return []
    })
}
